"""
Production Configuration
=======================

Production environment specific configuration settings.
Optimized for security and performance.
"""

from . import ProductionConfig

class Config(ProductionConfig):
    """Production configuration class."""
    
    # Security settings
    DEBUG = False
    TESTING = False
    
    # Use environment variables for sensitive data
    SECRET_KEY = os.environ.get('SECRET_KEY')
    JWT_SECRET_KEY = os.environ.get('JWT_SECRET_KEY')
    
    # Database configuration
    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL')
    SQLALCHEMY_ENGINE_OPTIONS = {
        'pool_size': 10,
        'pool_recycle': 3600,
        'pool_pre_ping': True,
    }
    
    # Production database settings
    MYSQL_DATABASE = os.environ.get('MYSQL_DATABASE', 'flask_enterprise_prod')
    
    # JWT configuration for production
    JWT_ACCESS_TOKEN_EXPIRES = timedelta(hours=2)  # Shorter expiry for security
    
    # CORS settings for production (restrictive)
    CORS_ORIGINS = os.environ.get('CORS_ORIGINS', '').split(',')
    
    # Rate limiting
    RATELIMIT_DEFAULT = "1000 per hour"
    
    # Logging configuration for production
    LOGGING_CONFIG = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'default': {
                'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s',
            },
            'detailed': {
                'format': '[%(asctime)s] %(levelname)s %(name)s %(funcName)s:%(lineno)d %(message)s'
            }
        },
        'handlers': {
            'console': {
                'class': 'logging.StreamHandler',
                'stream': 'ext://sys.stdout',
                'formatter': 'default',
                'level': 'WARNING'
            },
            'file': {
                'class': 'logging.handlers.RotatingFileHandler',
                'filename': 'logs/production.log',
                'maxBytes': 10485760,  # 10MB
                'backupCount': 10,
                'formatter': 'detailed',
                'level': 'INFO'
            },
            'error_file': {
                'class': 'logging.handlers.RotatingFileHandler',
                'filename': 'logs/error.log',
                'maxBytes': 10485760,  # 10MB
                'backupCount': 10,
                'formatter': 'detailed',
                'level': 'ERROR'
            }
        },
        'root': {
            'level': 'INFO',
            'handlers': ['console', 'file', 'error_file']
        },
        'loggers': {
            'sqlalchemy': {
                'level': 'WARNING',
                'handlers': ['file'],
                'propagate': False
            }
        }
    }